package com.hz.pay.center.service.strategy.impl;

import com.pay.common.enums.PayWayEnum;
import com.hz.pay.center.factory.PayFactory;
import com.hz.pay.center.model.PaySerialInfo;
import com.pay.common.resp.NetBankPayRespData;
import com.hz.pay.center.service.strategy.IStrategyPayService;
import com.hz.pay.center.utils.AlipayUtils;
import com.hz.pay.center.vo.PayVo;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 支付宝的网页支付
 */
@Service
public class AlipayPagePayStrategyPayServiceImpl implements IStrategyPayService, InitializingBean {

   @Autowired
   private AlipayUtils alipayUtils;

    @Override
    public NetBankPayRespData payment(PaySerialInfo paySerialInfo) {

        PayVo payVo = new PayVo();

        payVo.setSubject(paySerialInfo.getOrderDesc());

        payVo.setOutTradeNo(paySerialInfo.getPaySerialNo());

        payVo.setTotalAmount(paySerialInfo.getPayAmount());

        String payUrl = alipayUtils.alipayPapePay(payVo);


        NetBankPayRespData netBankPayRespData = new NetBankPayRespData();

        netBankPayRespData.setPayUrl(payUrl);

        return netBankPayRespData;
    }

    @Override
    public void afterPropertiesSet() throws Exception {

        PayFactory.concurrentHashMap.put(PayWayEnum.ALIPAY_PAGE_PAY.getCode(),this);

    }
}
